unit u_consultapadraoabas;

interface

uses
  Windows, Messages, ImgList, Controls, AdvOfficePager, DBClient,
  AdvOfficePagerStylers, Grids, DBGrids, JvExDBGrids, JvDBGrid, Graphics,
  AdvGlowButton, StdCtrls, AdvEdit, Forms, frm_empresafilial, ExtCtrls,
  Buttons, ToolWin, JvExForms, JvScrollPanel, Classes;

type
  TFRM_ConsultaPadraoAbas = class(TForm)
    AdvOfficePager: TAdvOfficePager;
    AbaConsulta: TAdvOfficePage;
    AdvOfficePagerOfficeStyler: TAdvOfficePagerOfficeStyler;
    jvMenuLateral: TJvScrollingWindow;
    btnNovo: TSpeedButton;
    pnlCentral: TPanel;
    pnlResumo: TPanel;
    lblTotal: TLabel;
    pnlFiltro: TPanel;
    GridConsulta: TJvDBGrid;
    ImageList: TImageList;
    FR_PesquisarEmpresaFilial: TFR_EmpresaFilial;
    pnlPesquisar: TPanel;
    lblFiltro: TLabel;
    cboFiltro: TComboBox;
    edtPesquisar: TAdvEdit;
    btnPesquisar: TAdvGlowButton;
    btnAlterar: TSpeedButton;
    btnExcluir: TSpeedButton;
    btnVisualizar: TSpeedButton;
    btnAtualizarLista: TAdvGlowButton;
    procedure FormShow(Sender: TObject);
    procedure FR_PesquisarEmpresaFilialbtnPesqEmpresaClick(Sender: TObject);
    procedure cboFiltroSelect(Sender: TObject);
    procedure edtPesquisarKeyPress(Sender: TObject; var Key: Char);
    procedure GridConsultaDblClick(Sender: TObject);
    procedure GridConsultaKeyDown(Sender: TObject; var Key: Word;Shift: TShiftState);
    procedure GridConsultaKeyPress(Sender: TObject; var Key: Char);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure GridConsultaTitleClick(Column: TColumn);

  private
    
  public

  end;

var
  FRM_ConsultaPadraoAbas: TFRM_ConsultaPadraoAbas;

implementation

uses u_dm_geral;

{$R *.dfm}

procedure TFRM_ConsultaPadraoAbas.FormShow(Sender: TObject);
begin
  AdvOfficePager.ActivePage := AbaConsulta;
  FR_PesquisarEmpresaFilial.edtCodEmpresa.IntValue := dmGeral.cdsConsultaEmpUserCOD_EMPRESA.AsInteger;
  FR_PesquisarEmpresaFilial.edtEmpresa.Text        := dmGeral.cdsConsultaEmpUserDESCRICAO_MULTIEMPRESA.AsString;
end;

procedure TFRM_ConsultaPadraoAbas.FR_PesquisarEmpresaFilialbtnPesqEmpresaClick(Sender: TObject);
begin
  FR_PesquisarEmpresaFilial.btnPesqEmpresaClick(Sender);
  btnPesquisar.Click;
end;

procedure TFRM_ConsultaPadraoAbas.cboFiltroSelect(Sender: TObject);
begin
  if cboFiltro.ItemIndex = 0 then
  begin
    edtPesquisar.Color   := clSilver;
    edtPesquisar.Enabled := false;
  end else
  begin
    edtPesquisar.Color   := clWhite;
    edtPesquisar.Enabled := true;
    if edtPesquisar.Visible then edtPesquisar.SetFocus;
  end;
end;

procedure TFRM_ConsultaPadraoAbas.edtPesquisarKeyPress(Sender: TObject; var Key: Char);
begin
  if key = #13 then btnPesquisar.Click;
end;

procedure TFRM_ConsultaPadraoAbas.GridConsultaDblClick(Sender: TObject);
begin
  btnAlterar.Click;
end;

procedure TFRM_ConsultaPadraoAbas.GridConsultaKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  if (key = VK_DELETE) then btnExcluir.Click;
end;

procedure TFRM_ConsultaPadraoAbas.GridConsultaKeyPress(Sender: TObject;
  var Key: Char);
begin
  if key = #13 then btnAlterar.Click;
end;

procedure TFRM_ConsultaPadraoAbas.FormKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  if (key = VK_INSERT) then btnNovo.Click;
end;

procedure TFRM_ConsultaPadraoAbas.GridConsultaTitleClick(Column: TColumn);
var
  i: integer;
begin
  for i:= 0 to GridConsulta.Columns.Count-1 do GridConsulta.Columns[i].Title.Font.Style := [];
  TClientDataSet(Column.Grid.DataSource.DataSet).IndexFieldNames := Column.FieldName;
  Column.Title.Font.Style := [fsBold];
end;

end.
